import {get, post } from '../../utils/request'
const state = {
    //用来保存查询出来的栏目信息
    products: [],
    total: 0
}
const actions = {
    findAllProduct(context, list) {
        //异步操作
        get('/product/pageQuery', list).then(res => {
            console.log(res.data, 'res.data');
            let response = res.data.list
            context.commit('setProducts', response)
            let total = res.data.total
            context.commit('setTotal', total)
        })
    },
    //保存栏目信息
    saveProduct(context, list) {
        let response = post('/product/saveOrUpdate', list)
        return response
    },
    //下架栏目信息
    deleteProduct(context, list) {
        let response = get('/product/offline', list)
        return response
    }
}
const mutations = {
    //修改state中的值
    setProducts(state, response) {
        state.products = response
    },
    setTotal(state, total) {
        state.total = total
    }
}
export default {
    namespaced: true,
    state,
    actions,
    mutations
}